package com.onlinesys.database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class DBOperator {

    private Connection conn = null;
    private PreparedStatement stmt = null;

    public ResultSet querySQL(String sql, List<Object> params) throws SQLException {
        conn = DBManager.getDBConnection();
        stmt = conn.prepareStatement(sql);
        for (int i = 0; i < params.size(); i++) {
            stmt.setObject(++i, params.get(i));
        }
        return stmt.executeQuery(sql);
    }

    public void executeUpdate(String sql) throws SQLException {
        conn = DBManager.getDBConnection();
        stmt = conn.prepareStatement(sql);
        stmt.executeQuery(sql);

        if (stmt != null) {
            stmt.close();
        }
        if (conn != null) {
            conn.close();
        }
    }

}
